#!/usr/bin/bash

max=70
min=30
step=10

MAX=100
MIN=0

if [[ $1 == "" ]] ; then
  echo "keys: inc dec
  sway-tools-volume inc   sway-tools-volume + $step
  sway-tools-volume dec   sway-tools-volume - $step
  sway-tools-volume get
  sway-tools-volume max   sway-tools-volume = $max
  sway-tools-volume min   sway-tools-volume = $min
  sway-tools-volume mute   volume mute
  sway-tools-volume - <value>   > $MIN
  sway-tools-volume + <value>   < $MAX
  sway-tools-volume = <num>   $MIN < <num> > $MAX
"
  exit 1
else
  char=$1
  num=$2
fi

if [[ "get" == $char ]] ; then
  return `get volume`

elif [[ "inc" == $char ]] ; then
  sway-tools-volume + $step
elif [[ "dec" == $char ]] ; then
  sway-tools-volume - $step

elif [[ "min" == $char ]] ; then
  sway-tools-volume = $min
elif [[ "max" == $char ]] ; then
  sway-tools-volume = $max

elif [[ "mute" == $char ]] ; then
    pactl set-sink-mute @DEFAULT_SINK@ toggle # off \ on

elif [[ "+" == $char ]] ; then
  sum=$(( `sway-tools-volume get` + $num))
   
  if [[ $sum > $MAX ]] ; then
    sum=$MIN
  fi
  
  pactl set-sink-volume @DEFAULT_SINK@ +$num%
  # pactl set-sink-volume @DEFAULT_SINK@ $sum%
elif [[ "-" == $char ]] ; then
  sum=$(( `sway-tools-volume get` - $num)) 

  if [[ $sum < $MIN ]] ; then
    sum=$MIN
  fi
  
  pactl set-sink-volume @DEFAULT_SINK@ -$num%
elif [[ "=" == $char ]] ; then
  # IF [[ $num > $MAX ]] ; THEN
  #	 num=$MAX
  # FLIF [[ $num < $MIN ]] ; THEN
  #	 num=$MIN
  # FI
  
  pactl set-sink-volume @DEFAULT_SINK@ $num%
else
     exit `false`
fi

